package com.demo.study.creative.d02_abstractFactory.normal;

import com.demo.study.creative.d02_abstractFactory.Sender;
import com.demo.study.creative.d02_abstractFactory.impl.MailSender;
import com.demo.study.creative.d02_abstractFactory.impl.SmsSender;

/**
 * 普通工厂
 *
 * @author Baymax
 * @since 2021/1/18
 */
public class OrdinaryFactory {
    public static Sender produceSender(String type) {
        Sender sender = null;
        if ("mail".equals(type)) {
            sender = new MailSender();
        } else if ("sms".equals(type)) {
            sender = new SmsSender();
        } else {
            System.out.println("type is error!");
        }
        return sender;
    }

    public static Sender getSender(Class<? extends Sender> sender) {
        Sender sender1 = null;
        try {
            sender1 = sender.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return sender1;
    }
}